package com.atguigu.controller;

import com.atguigu.entity.Student01;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: KeepFresh
 * @time: 2021/4/15 19:02
 */
public class TwoServlet extends HttpServlet {

    // 处理业务，得到处理结果--------查询学员信息
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Student01 s1 = new Student01(10, "mike");
        Student01 s2 = new Student01(20, "allen");
        Student01 s3 = new Student01(10, "smith");
        List stuList = new ArrayList();
        stuList.add(s1);
        stuList.add(s2);

        // 将处理结果添加到请求作用域对象
        req.setAttribute("key", stuList);

        // 通过请求转发方案，向Tomcat申请调用user_show.jsp
        // 同时将request与response通过tomcat交给user_show.jsp使用
        req.getRequestDispatcher("/user_show.jsp").forward(req,resp);
    }

}
